import numpy as np

# ---- run Test
num: int = 0


def runTest(fun):
    global num
    print('----------------------', num)
    fun()
    num += 1
    print()


# -------------------------------------------- tests:

def test_str():
    ret = np.char.add(['welcome', 'url'], [' to C net', 'is c.biancheng.net'])
    print(len(ret))
    print(ret)

    print()
    print(np.char.multiply('c.biancheng.net', 3))
    print(np.char.center("c.bianchneg.net", 20, '*'))
    # print(np.char.left("c.bianchneg.net", 20, '*'))
    # print(np.char.right("c.bianchneg.net", 20, '*'))

    print()
    print(np.char.upper("Welcome To Python"))
    print(np.char.upper("Welcome To Python"))
    print(np.char.lower("WELCOME TO MYHOME"))
    print(np.char.upper("Welcome To Python"))
    print(np.char.split("Welcome To Python"), sep=" ")

    print()
    print("Splitting the String line by line..")
    print(np.char.splitlines("Welcome\nTo\nPython"))


def test_str2():
    print(np.char.join(':', 'Love'))
    # 也可指定多个分隔符
    print(np.char.join([':', '-'], ['Love', 'Python']))


def test_encode():
    import numpy as npy
    # cp500国际编码
    encode_str = npy.char.encode("Welcome to China", 'cp500')
    decode_str = npy.char.decode(encode_str, 'cp500')
    print(encode_str)
    print(decode_str)

    print()
    encode_str = npy.char.encode("Welcome to China", encoding='utf8')
    decode_str = npy.char.decode(encode_str, encoding='utf8')
    print(encode_str)
    print(decode_str)


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    runTest(test_str)
    runTest(test_str2)
    runTest(test_encode)
